package com.jjy.controller;

import com.jjy.pojo.FlightsTwoAirports;
import com.jjy.service.FlightService;
import com.jjy.util.ResultObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;

@RestController
@RequestMapping("/flight/")
public class FlightController {

    @Autowired
    private FlightService flightService;
    @Autowired
    private ResultObject result;

    @RequestMapping("select")
    public ResultObject select(FlightsTwoAirports flightsTwoAirports, String date) {
        if (date != null && !date.equals("")){
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            try {
                flightsTwoAirports.setFight_date((Date) dateFormat.parse(date));
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
        result.setStatus(1);
        result.setResult(flightService.select(flightsTwoAirports));
        return result;
    }

    @RequestMapping("selectTicket")
    public ResultObject selectTicket(int id) {
        result.setStatus(1);
        result.setResult(flightService.selectTickets(id));
        return result;
    }
}
